home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / HFTUBE.ZIP / TUBE.ASM < prev    next >
Assembly Source File  |  1995-05-06  |  18KB  |  304 lines

  1. CodeTube                     Segment   Para Use16
  2.                              Assume    Cs:CodeTube
  3.                              Public    VoxelTubeInit,VoxelTubeFree
  4.                              Public    VoxelTube,DrawVoxelTube
  5.  
  6. ; ===========================================================================
  7. ;   Initialize voxel tube
  8. ;   /////////////////////
  9. ;   description: Allocate memory and calculate required tables for voxel tube
  10. ;                routine. Use procedure VoxelTubeFree for releasing allocated
  11. ;                memory units.
  12. ;         input: Nothing
  13. ;       returns: CF is set if not enough memory, else Ax=output segment
  14. ; ===========================================================================
  15.   VoxelTubeInit              Proc      Far
  16.                              .386
  17.                              Mov       Ah,48h
  18.                              Mov       Bx,23A0h                              ; Amount of memory required
  19.                              Int       21h
  20.                              Jc        NotEnoughMemory
  21.                              Mov       Cs:[OutputSeg],Ax
  22.                              Add       Ax,1000h                              ; Output segment size in paragraphs
  23.                              Mov       Cs:[PixelPointerSeg],Ax
  24.                              Add       Ax,0FA0h                              ; Pixel pointer table size
  25.                              Mov       Cs:[ProjectTableseg],Ax
  26.                              Mov       Es,Ax
  27.  
  28.  
  29. ; By setting limit values in formula
  30. ;      e=zl·yl'/(a·yl-yl')
  31. ; we get eye distance from projection plane which will be placed in formula
  32. ;      y'=a·e·y/(z+e)
  33. ; which can be used to calculate all projected columns
  34. ; Below are exlanations for used parameters:
  35. ;     e   eye distance from projection plane                        (0.06477)
  36. ;     zl  a edge distance of the column from projection plane            (62)
  37. ;     yl  a edge height of the column                                   (255)
  38. ;     yl' a edge projected height of the column at specified distance    (33)
  39. ;     a   the projected height of 1 unit height column at distance 0    (126)
  40. ;     y'  projected value of specified column
  41. ;     y   height of the column
  42. ;     z   distance of the column from the plane
  43.  
  44.          zl                  Equ       62
  45.          yl                  Equ       255
  46.          ylp                 Equ       33
  47.          a                   Equ       126
  48.          e                   Equ       zl*ylp/(a*yl-ylp)
  49.  
  50.                              Mov       Bx,3E00h
  51.  
  52. ;                             Mov       Ecx,e*00010000h+003E0000h
  53.                              Mov       Ecx,2510+003E0000h
  54.          ProjectTableLoop2:  Mov       Esi,318882
  55.          ProjectTableLoop1:  Mov       Eax,Esi
  56.                              Xor       Edx,Edx
  57.                              Div       Ecx
  58.                              Add       Dx,Dx
  59.                              Adc       Ax,01h
  60.                              Cmp       Ax,0080h
  61.                              Jb        NoRadiusFix
  62.                              Mov       Al,7Fh
  63.          NoRadiusFix:        Mov       Es:[Bx],Al
  64. ;                             Add       Esi,a*e*00010000h
  65.                              Add       Esi,318882
  66.                              Inc       Bl
  67.                              Jnz       ProjectTableLoop1
  68.                              Mov       Byte Ptr Es:[Bx],Bl
  69.                              Sub       Ecx,00010000h
  70.                              Dec       Bh
  71.                              Jns       ProjectTableLoop2
  72.                              Mov       Bx,3F00h
  73.          ProjectTableLoop3:  Mov       Byte Ptr Es:[Bx],00h
  74.                              Inc       Bl
  75.                              Jnz       ProjectTableLoop3
  76.  
  77.  
  78.  
  79. ;                             Mov       Bx,3E00h
  80. ;                             Mov       Ecx,003E21E4h
  81. ;         ProjectTableLoop2:  Xor       Esi,Esi
  82. ;         ProjectTableLoop1:  Xor       Edx,Edx
  83. ;                             Mov       Eax,Esi
  84. ;                             Div       Ecx
  85. ;                             Inc       Ax
  86. ;                             Cmp       Ax,0080h
  87. ;                             Jb        NoRadiusFix
  88. ;                             Mov       Al,7Fh
  89. ;         NoRadiusFix:        Mov       Es:[Bx],Al
  90. ;                             Add       Esi,00059AA6h
  91. ;                             Inc       Bl
  92. ;                             Jnz       ProjectTableLoop1
  93. ;                             Sub       Ecx,00010000h
  94. ;                             Dec       Bh
  95. ;                             Jns       ProjectTableLoop2
  96. ;                             Mov       Bx,3F00h
  97. ;         ProjectTableLoop3:  Mov       Byte Ptr Es:[Bx],00h
  98. ;                             Inc       Bl
  99. ;                             Jnz       ProjectTableLoop3
  100.  
  101.                              Mov       Ax,Cs:[OutputSeg]
  102.                              Clc
  103.          NotEnoughMemory:    RetF
  104.  
  105.   VoxelTubeInit              EndP
  106.  
  107. ; ===========================================================================
  108. ;   Release Voxel tube
  109. ;   //////////////////
  110. ;   description: Free allocater memory units for voxel tube
  111. ;         input: Nothing
  112. ;       returns: CF is set if can't release memory
  113. ; ===========================================================================
  114.   VoxelTubeFree              Proc      Far
  115.                              Mov       Ah,49h
  116.                              Mov       Es,Cs:[OutputSeg]
  117.                              Int       21h
  118.                              RetF
  119.   VoxelTubeFree              EndP
  120.  
  121.  
  122. ; ===========================================================================
  123. ;   Calculate voxel tube
  124. ;   ////////////////////
  125. ;   description: Draw voxel tube bitmap to the output segment by using radius
  126. ;                and color table. Use procedure DrawVoxelTube to draw bitmap
  127. ;                right on the screen.
  128. ;         input: Ds=segment to wall radiuses (table size 512x128)
  129. ;                Gs=segment to wall colors (table size 512x128)
  130. ;                Dx=tube rotate value (0-511)
  131. ;       returns: Nothing
  132. ; ===========================================================================
  133.   VoxelTube                  Proc      Far
  134.                              .386
  135.  
  136.                              Mov       Ax,Cs:[OutputSeg]                     ; Move output segment to Es
  137.                              Mov       Es,Ax
  138.                              Mov       Ax,Cs:[ProjectTableSeg]               ; Move project table -segment to Fs
  139.                              Mov       Fs,Ax
  140.                              Mov       Bp,01FFh                              ; Line counter
  141.  
  142.          RowChange:          Mov       Si,Bp                                 ; Move read line number to Si
  143.                              Sub       Si,Dx
  144.                              Jnc       NoOverflow
  145.                              Add       Si,0200h
  146.          NoOverflow:         Xor       Bh,Bh                                 ; Start distance
  147.                              Mov       Ah,Cs:[Bp+LineStart]                  ; Maximum radius
  148.                              Mov       Di,Bp                                 ; Output line
  149.  
  150.          MoveRayLoop:        Mov       Bl,[Si]                               ; Read radius
  151.                              Mov       Al,Fs:[Bx]                            ; Project radius
  152.                              Sub       Al,Ah                                 ; Test if projected radius is shortest by now
  153.                              Jc        DrawLine2
  154.          DrawRet2:           Mov       Bl,[Si+0200h]                         ; Read next radius
  155.                              Add       Si,0400h                              ; Move ray position
  156.                              Mov       Al,Fs:[Bx+0100h]                      ; Projected radius
  157.                              Add       Bh,02h                                ; Increase distance
  158.                              Sub       Al,Ah                                 ; Test if projected radius is shortest by now
  159.                              Jnc       MoveRayLoop
  160.          DrawLine1:          Add       Ah,Al                                 ; Move new projected radius to Ah
  161.                              Jz        RowEnd                                ; If projected radius is 128, move to next row
  162.                              Mov       Cl,Gs:[Si-0200h]                      ; Take wall color
  163.                              Sub       Cl,Bh                                 ; Decrease distance color from wall color
  164.          DrawLineLoop1:      Mov       Es:[Di],Cl                            ; Draw as many pixels as is the difference
  165.                              Add       Di,0200h                              ;   between new and old projected radius
  166.                              Inc       Al
  167.                              Jnz       DrawLineLoop1
  168.                              Jmp       MoveRayLoop                           ; Back to the ray loop
  169.  
  170.          DrawLine2:          Add       Ah,Al                                 ; ... see above
  171.                              Jz        RowEnd
  172.                              Mov       Cl,Gs:[Si]
  173.                              Sub       Cl,Bh
  174.          DrawLineLoop2:      Mov       Es:[Di],Cl
  175.                              Add       Di,0200h
  176.                              Inc       Al
  177.                              Jnz       DrawLineLoop2
  178.                              Jmp       DrawRet2
  179.  
  180.          RowEnd:             Dec       Bp                                    ; Next row
  181.                              Jns       RowChange                             ; If no more, exit
  182.                              RetF
  183.  
  184.          ProjectTableSeg     Dw        ?
  185.          OutputSeg           Dw        ?
  186.          LineStart           Db        06Ch,06Ch,06Ch,06Ch,06Ch,06Ch,06Ch,06Ch
  187.                              Db        06Dh,06Dh,06Dh,06Dh,06Dh,06Dh,06Eh,06Eh
  188.                              Db        06Eh,06Eh,06Fh,06Fh,06Fh,070h,070h,070h
  189.                              Db        071h,071h,072h,072h,073h,073h,074h,074h
  190.                              Db        075h,076h,076h,077h,078h,078h,079h,07Ah
  191.                              Db        07Bh,07Bh,07Ch,07Dh,07Eh,07Fh,07Dh,07Ah
  192.                              Db        078h,076h,074h,072h,070h,06Eh,06Dh,06Bh
  193.                              Db        069h,068h,066h,065h,064h,062h,061h,060h
  194.                              Db        05Fh,05Dh,05Ch,05Bh,05Bh,059h,058h,057h
  195.                              Db        057h,056h,055h,054h,053h,053h,052h,051h
  196.                              Db        051h,050h,050h,04Fh,04Eh,04Eh,04Dh,04Dh
  197.                              Db        04Ch,04Ch,04Bh,04Bh,04Ah,04Ah,04Ah,049h
  198.                              Db        049h,049h,048h,048h,047h,047h,047h,047h
  199.                              Db        046h,046h,046h,046h,046h,045h,045h,045h
  200.                              Db        045h,045h,044h,044h,044h,044h,044h,044h
  201.                              Db        044h,044h,044h,044h,044h,044h,044h,044h
  202.                              Db        044h,044h,044h,044h,044h,044h,044h,044h
  203.                              Db        044h,044h,044h,044h,044h,044h,045h,045h
  204.                              Db        045h,045h,045h,046h,046h,046h,046h,046h
  205.                              Db        047h,047h,047h,047h,048h,048h,049h,049h
  206.                              Db        049h,04Ah,04Ah,04Ah,04Bh,04Bh,04Ch,04Ch
  207.                              Db        04Dh,04Dh,04Eh,04Eh,04Fh,050h,050h,051h
  208.                              Db        051h,052h,053h,053h,054h,055h,056h,057h
  209.                              Db        057h,058h,059h,05Bh,05Bh,05Ch,05Dh,05Fh
  210.                              Db        060h,061h,062h,064h,065h,066h,068h,069h
  211.                              Db        06Bh,06Dh,06Eh,070h,072h,074h,076h,078h
  212.                              Db        07Ah,07Dh,07Fh,07Eh,07Dh,07Ch,07Bh,07Bh
  213.                              Db        07Ah,079h,078h,078h,077h,076h,076h,075h
  214.                              Db        074h,074h,073h,073h,072h,072h,071h,071h
  215.                              Db        070h,070h,070h,06Fh,06Fh,06Fh,06Eh,06Eh
  216.                              Db        06Eh,06Eh,06Dh,06Dh,06Dh,06Dh,06Dh,06Dh
  217.                              Db        06Ch,06Ch,06Ch,06Ch,06Ch,06Ch,06Ch,06Ch
  218.  
  219.                              Db        06Ch,06Ch,06Ch,06Ch,06Ch,06Ch,06Ch,06Ch
  220.                              Db        06Dh,06Dh,06Dh,06Dh,06Dh,06Dh,06Eh,06Eh
  221.                              Db        06Eh,06Eh,06Fh,06Fh,06Fh,070h,070h,070h
  222.                              Db        071h,071h,072h,072h,073h,073h,074h,074h
  223.                              Db        075h,076h,076h,077h,078h,078h,079h,07Ah
  224.                              Db        07Bh,07Bh,07Ch,07Dh,07Eh,07Fh,07Dh,07Ah
  225.                              Db        078h,076h,074h,072h,070h,06Eh,06Dh,06Bh
  226.                              Db        069h,068h,066h,065h,064h,062h,061h,060h
  227.                              Db        05Fh,05Dh,05Ch,05Bh,05Bh,059h,058h,057h
  228.                              Db        057h,056h,055h,054h,053h,053h,052h,051h
  229.                              Db        051h,050h,050h,04Fh,04Eh,04Eh,04Dh,04Dh
  230.                              Db        04Ch,04Ch,04Bh,04Bh,04Ah,04Ah,04Ah,049h
  231.                              Db        049h,049h,048h,048h,047h,047h,047h,047h
  232.                              Db        046h,046h,046h,046h,046h,045h,045h,045h
  233.                              Db        045h,045h,044h,044h,044h,044h,044h,044h
  234.                              Db        044h,044h,044h,044h,044h,044h,044h,044h
  235.                              Db        044h,044h,044h,044h,044h,044h,044h,044h
  236.                              Db        044h,044h,044h,044h,044h,044h,045h,045h
  237.                              Db        045h,045h,045h,046h,046h,046h,046h,046h
  238.                              Db        047h,047h,047h,047h,048h,048h,049h,049h
  239.                              Db        049h,04Ah,04Ah,04Ah,04Bh,04Bh,04Ch,04Ch
  240.                              Db        04Dh,04Dh,04Eh,04Eh,04Fh,050h,050h,051h
  241.                              Db        051h,052h,053h,053h,054h,055h,056h,057h
  242.                              Db        057h,058h,059h,05Bh,05Bh,05Ch,05Dh,05Fh
  243.                              Db        060h,061h,062h,064h,065h,066h,068h,069h
  244.                              Db        06Bh,06Dh,06Eh,070h,072h,074h,076h,078h
  245.                              Db        07Ah,07Dh,07Fh,07Eh,07Dh,07Ch,07Bh,07Bh
  246.                              Db        07Ah,079h,078h,078h,077h,076h,076h,075h
  247.                              Db        074h,074h,073h,073h,072h,072h,071h,071h
  248.                              Db        070h,070h,070h,06Fh,06Fh,06Fh,06Eh,06Eh
  249.                              Db        06Eh,06Eh,06Dh,06Dh,06Dh,06Dh,06Dh,06Dh
  250.                              Db        06Ch,06Ch,06Ch,06Ch,06Ch,06Ch,06Ch,06Ch
  251.  
  252.   VoxelTube                  EndP
  253.  
  254.  
  255. ; ===========================================================================
  256. ;   Draw calculated tube to the screen
  257. ;   //////////////////////////////////
  258. ;   description: Draw voxel tube bitmap which is calculated to the memory on
  259. ;                the screen in the shape of circle.
  260. ;         input: Es=video segment (320x200x256)
  261. ;       returns: Nothing
  262. ; ===========================================================================
  263.   DrawVoxelTube              Proc      Far
  264.                              .486
  265.                              Push      Ds
  266.  
  267.                              Mov       Ax,Cs:[OutputSeg]                     ; Read data from output segment
  268.                              Mov       Fs,Ax                                 ;   and store it to video segment
  269.                              Mov       Ax,Cs:[PixelPointerSeg]               ;   via pixel read pointers
  270.                              Mov       Ds,Ax
  271.                              Mov       Bp,0F9FEh
  272.                              Mov       Bx,0FFFCh
  273.                              Mov       Di,0FA00h
  274.  
  275.          DrawTubeLoop:       Mov       Si,Ds:[Bp]                            ; Read a read position
  276.                              Add       Bx,04h                                ; Increase output pointer A
  277.                              Mov       Al,Fs:[Si]                            ; Read data A from read position
  278.                              Mov       Dl,Fs:[Si+0100h]                      ; Read data B from the opposite position of the tube
  279.                              Mov       Si,Ds:[Bp-02h]                        ; Read another read position
  280.                              Sub       Di,04h                                ; Decrease output pointer B
  281.                              Mov       Ah,Fs:[Si]                            ; Read data A...
  282.                              Mov       Dh,Fs:[Si+0100h]
  283.                              Mov       Si,Ds:[Bp-04h]
  284.                              Bswap     Eax                                   ; Prepare higher bytes for modification
  285.                              BSwap     Edx
  286.                              Mov       Ah,Fs:[Si]
  287.                              Mov       Dh,Fs:[Si+0100h]
  288.                              Mov       Si,Ds:[Bp-06h]
  289.                              Mov       Dl,Fs:[Si+0100h]
  290.                              Mov       Es:[Di],Edx                           ; Output data B to output pointer B
  291.                              Sub       Bp,08h                                ; Decrease table pointer
  292.                              Mov       Al,Fs:[Si]
  293.                              Bswap     Eax                                   ; Order data A for output
  294.                              Mov       Es:[Bx],Eax                           ; Output data A to output pointer A
  295.                              Jnc       DrawTubeLoop                          ; If all screen copied, exit
  296.  
  297.                              Pop       Ds
  298.                              RetF
  299.  
  300.          PixelPointerSeg     Dw        ?
  301.   DrawVoxelTube              EndP
  302.  
  303. CodeTube                     EndS
  304.